<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="外挂账号" prop="waiguaUsername">
      <el-input v-model="dataForm.waiguaUsername" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="账号等级" prop="waiguaGrade">
      <el-input v-model="dataForm.waiguaGrade" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="简单描述" prop="waiguaGrade">
      <el-input v-model="dataForm.waiguaDescribe" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="外挂类型" prop="waiguaType">
    <el-select v-model="dataForm.waiguaType" multiple placeholder="请选择">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
    </el-form-item>

 <el-alert
    title="以下内容均为选填"
    type="success"
    :closable="false">
  </el-alert>

    <el-form-item label="封禁状态" >
      <el-radio v-model="dataForm.sealState" label="0">未封禁</el-radio>
      <el-radio v-model="dataForm.sealState" label="1">一天</el-radio>
      <el-radio v-model="dataForm.sealState" label="2">三天</el-radio>
      <el-radio v-model="dataForm.sealState" label="3">永久</el-radio>
    </el-form-item>
    <el-form-item label="封禁起始" >
      <el-date-picker
      v-model="dataForm.sealStartTime"
      type="datetime"
      placeholder="选择日期时间"
      default-time="12:00:00">
    </el-date-picker>
    </el-form-item>
    <el-form-item label="封禁结束" >
      <el-date-picker
      v-model="dataForm.sealEndTime"
      type="datetime"
      placeholder="选择日期时间"
      default-time="12:00:00">
    </el-date-picker>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        options: [{
          value: '1',
          label: '透视'
        }, {
          value: '2',
          label: '无后座'
        }, {
          value: '3',
          label: '自瞄'
        }, {
          value: '4',
          label: '锁头'
        }, {
          value: '5',
          label: '穿墙'
        }],
        dataForm: {
          id: 0,
          waiguaUsername: '',
          waiguaGrade: '',
          waiguaDescribe: '',
          waiguaType: [],
          sealState: '0',
          sealStartTime: '',
          sealEndTime: '',
          waiguaId: ''
        },
        dataRule: {
          waiguaUsername: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          waiguaGrade: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          waiguaType: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          sealState: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          sealStartTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          sealEndTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    computed: {
      userId: {
        get () { return this.$store.state.user.id }
      }
    },
    methods: {
      init (id) {
        this.dataForm.waiguaDescribe =''
        console.log("id",id)
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/waiguagg/info/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              console.log(data)
              if (data && data.code === 0) {
                this.dataForm.waiguaUsername = data.info.waiguaUsername
                this.dataForm.waiguaGrade = data.info.waiguaGrade
                this.dataForm.waiguaType = data.info.waiguaType
                this.dataForm.sealState = data.info.sealState
                this.dataForm.sealStartTime = data.info.sealStartTime
                this.dataForm.sealEndTime = data.info.sealEndTime
                this.dataForm.waiguaDescribe = data.info.waiguaDescribe
                this.dataForm.waiguaId = data.info.waiguaId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/waiguagg/info/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'waiguaInfoId': this.dataForm.id || undefined,
                'waiguaUsername': this.dataForm.waiguaUsername,
                'waiguaGrade': this.dataForm.waiguaGrade,
                'waiguaDescribe': this.dataForm.waiguaDescribe,
                'waiguaType': this.dataForm.waiguaType,
                'sealState': this.dataForm.sealState,
                'sealStartTime': this.dataForm.sealStartTime,
                'sealEndTime': this.dataForm.sealEndTime,
                'reportuserId': this.userId,
                'waiguaId': this.dataForm.waiguaId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
